/* 
路由器模块
*/
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login/index.vue'
import Home from '@/views/Home/index.vue'
import Course from '@/views/Home/Course/index.vue'
import Game from '@/views/Home/Game/index.vue'
import News from '@/views/Home/News/index.vue'

// 安装vue-router插件
Vue.use(VueRouter)

// 创建路由器, 并配置路由表, 注册路由
const router = new VueRouter({
  // 路由表
  routes: [
    {
      path: '/login',
      component: Login
    },
    {
      path: '/home',
      component: Home,
      /* 写法一: 在父路由中配置redirect */
      // redirect: '/home/course',
      children: [
        {
          path: '/home/course',  // 完整写法
          component: Course
        },
        {
          path: 'game',  // 简写  => /home/game
          component: Game
        },
        {
          path: 'news',  // 简写  => /home/news
          component: News
        },
        /* 写法二: 配置自动跳转的子路由 */
        {
          path: '',
          redirect: '/home/course'
        }
      ]
    },
    // 自动跳转的路由
    {
      path: '/',
      redirect: '/home'
    }
  ]
})

// 暴露路由器
export default router

